package com.sghj.utils;



import cn.hutool.core.util.CharsetUtil;
import cn.hutool.crypto.SmUtil;
import cn.hutool.crypto.symmetric.SM4;

/**
 * @author xrx
 * @Date 2022/6/30
 * @apiNote
 */
public final class SM4Utils {

    /**
     * 秘钥
     */
    //public static String SM4_KEY = "2c81b51b30feffbd";

    public static byte[] SM4_KEY = {0x01, 0x23, 0x45, 0x67, (byte) 0x80, (byte) 0xab, (byte) 0xad, (byte) 0xef, (byte) 0xfe, (byte) 0xdc, (byte) 0xca, (byte) 0x98, (byte) 0x96, 0x54, 0x32, 0x13};

    public static final String ENCODING = "UTF-8";

    public static SM4 sm4 = SmUtil.sm4(SM4_KEY);

    /**
     * 加密
     * @param Str
     * @return
     */
    public static String encrypt(String Str) {
       return sm4.encryptHex(Str, CharsetUtil.CHARSET_UTF_8);
    }

    /**
     * 解密
     * @param Str
     * @return
     */
    public static String decrypt(String Str) {
       return sm4.decryptStr(Str,CharsetUtil.CHARSET_UTF_8);
    }
    public static void main(String[] args) {
       // System.out.println(decrypt("95d73c280fe87496d6e21071834e66db832ccd471d3cdb2c008decbe0078e5cd0ce7796d17c9976572ed41b22a34de31259aeabb22b17b52490250431525332a72daed8d0d0054f79db0b76b0dc3dece3739a2019883c90b8915b7ac824c2883"));
        System.out.println(encrypt("123456@"));

    }
}
